package com.weishui.dimensionalbarcode.app;

import java.awt.EventQueue;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;

import com.jtattoo.plaf.mcwin.McWinLookAndFeel;
import com.weishui.dimensionalbarcode.listener.ButtonActionListener;

public class AppWindoow {

	public JTextArea textAreaShowContent;
	public JTextArea textAreaContent;
	private JFrame frame;
	
	public JTextPane textPaneImage;
	public JTextPane textPaneSelectImage;

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			UIManager.setLookAndFeel(new McWinLookAndFeel());
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AppWindoow window = new AppWindoow();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application
	 */
	public AppWindoow() {
		createContents();
	}

	/**
	 * Initialize the contents of the frame
	 */
	private void createContents() {
		frame = new JFrame();
		frame.getContentPane().setLayout(null);
		frame.setTitle("二维码编码与解码");
		frame.setBounds(100, 100, 736, 590);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);

		final JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "编码", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		panel.setLayout(null);
		panel.setBounds(10, 10, 708, 260);
		frame.getContentPane().add(panel);

		final JButton buttonEncode = new JButton();
		buttonEncode.setText("编码");
		buttonEncode.setBounds(368, 226, 106, 21);
		buttonEncode.setActionCommand("encode");
		buttonEncode.addActionListener(new ButtonActionListener(this));
		panel.add(buttonEncode);

		final JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBorder(new TitledBorder(null, "编码内容", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane.setBounds(10, 20, 466, 200);
		panel.add(scrollPane);

		textAreaContent = new JTextArea();
		textAreaContent.setLineWrap(true);
		scrollPane.setViewportView(textAreaContent);

		final JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBorder(new TitledBorder(null, "预览", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		scrollPane_1.setBounds(482, 20, 200, 200);
		panel.add(scrollPane_1);

		textPaneImage = new JTextPane();
		textPaneImage.setEditable(false);
		scrollPane_1.setViewportView(textPaneImage);

		final JButton buttonSaveAs = new JButton();
		buttonSaveAs.setText("另存为");
		buttonSaveAs.setBounds(575, 226, 106, 21);
		buttonSaveAs.setActionCommand("save");
		buttonSaveAs.addActionListener(new ButtonActionListener(this));
		panel.add(buttonSaveAs);

		final JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "解码", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		panel_1.setLayout(null);
		panel_1.setBounds(10, 276, 708, 266);
		frame.getContentPane().add(panel_1);

		final JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBorder(new TitledBorder(null, "预览", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		scrollPane_2.setBounds(10, 24, 200, 200);
		panel_1.add(scrollPane_2);

		textPaneSelectImage = new JTextPane();
		textPaneSelectImage.setEditable(false);
		scrollPane_2.setViewportView(textPaneSelectImage);

		final JPanel panel_2 = new JPanel();
		panel_2.setLayout(new GridLayout(1, 0));
		panel_2.setBorder(new TitledBorder(null, "解码结果", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
		panel_2.setBounds(216, 24, 467, 200);
		panel_1.add(panel_2);

		textAreaShowContent = new JTextArea();
		textAreaShowContent.setEditable(true);
		textAreaShowContent.setLineWrap(true);
		panel_2.add(textAreaShowContent);

		final JButton buttonSelectImage = new JButton();
		buttonSelectImage.setText("选择二维码");
		buttonSelectImage.setBounds(12, 230, 106, 21);
		buttonSelectImage.setActionCommand("select");
		buttonSelectImage.addActionListener(new ButtonActionListener(this));
		panel_1.add(buttonSelectImage);

		final JButton buttonDecode = new JButton();
		buttonDecode.setText("解码");
		buttonDecode.setBounds(218, 230, 106, 21);
		buttonDecode.setActionCommand("decode");
		buttonDecode.addActionListener(new ButtonActionListener(this));
		panel_1.add(buttonDecode);
	}

}
